package com.fanbuchi.fukua.api;

import android.text.TextUtils;
import android.util.SparseArray;

import com.fanbuchi.fukua.entity.UserEntity;
import com.fanbuchi.fukua.utils.PassUtils;
import com.fanbuchi.fukua.validate.RegValidate;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.FormEncodingBuilder;

/**
 * Created by Administrator on 2015/10/23.
 */
public class UserAPI extends API {
    private  static  String   mUser=getHost()+"/user";
    public static UserAPI mAPI;

    private  UserAPI(){
    }
    public static UserAPI getAPI(){
        if (mAPI==null){
            mAPI = new UserAPI();
        }
        return mAPI;
    }

    public  SparseArray<String> createUser(UserEntity user,Callback callback) {
        SparseArray<String> _result= RegValidate.createUserValidate(user);
       if (_result.size()>0){
           return _result;
       }
        FormEncodingBuilder builder=new FormEncodingBuilder()
                .add("userName",user.getUserName())
                .add("nickName",user.getNickName())
                .add("password", PassUtils.encode(user.getPassword(), user.getUserName()));
        normalPostRequest(builder,callback,mUser);
        return null;
    }
}
